home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / submission_info.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  1.9 KB  |  63 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import logging
  20.  
  21. from datetime import datetime
  22.  
  23. from checkbox.lib.safe import safe_md5sum
  24.  
  25. from checkbox.properties import String
  26. from checkbox.plugin import Plugin
  27.  
  28.  
  29. class SubmissionInfo(Plugin):
  30.  
  31.     # Submission ID to exchange information with the server.
  32.     submission_id = String(required=False)
  33.  
  34.     def register(self, manager):
  35.         super(SubmissionInfo, self).register(manager)
  36.         self._system_id = None
  37.  
  38.         for (rt, rh) in [
  39.              ("report", self.report),
  40.              ("report-system_id", self.report_system_id)]:
  41.             self._manager.reactor.call_on(rt, rh)
  42.  
  43.     def report_system_id(self, system_id):
  44.         self._system_id = system_id
  45.  
  46.     def report(self):
  47.         submission_id = self.submission_id
  48.         if not submission_id:
  49.             if not self._system_id:
  50.                 return
  51.  
  52.             fingerprint = safe_md5sum()
  53.             fingerprint.update(self._system_id)
  54.             fingerprint.update(str(datetime.utcnow()))
  55.             submission_id = fingerprint.hexdigest()
  56.  
  57.         message = submission_id
  58.         logging.info("Submission ID: %s", message)
  59.         self._manager.reactor.fire("report-submission_id", message)
  60.  
  61.  
  62. factory = SubmissionInfo
  63.